package com.hw.ssh.service;

import com.hw.ssh.dao.BaseDao;
import com.hw.ssh.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true)//没有报Could not obtain transaction-synchronized Session for current thread
public class UserService {
    @Autowired
    private BaseDao<User> userDao;

    public List<User> list() {
        return userDao.find( "from User" );

    }

    @Transactional
    public void add(User user) {
        User user1 = userDao.get( "from User where id =1" );
        user1.setName( user.getName() );
        // userDao.update( user1 );不需要显示调用,@Transactional会持久化查出的对象
    }


}
